package ${packageName};

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${commonPageDTOLocation};
import ${dtoLocation} ;
import ${doLocation} ;
import ${mapperLocation} ;
import ${cpoierLocation} ;
import ${serviceLocation} ;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ${className} extends ServiceImpl<${mapperClassName}, ${doClassName}> implements ${serviceClassName} {
    private final ${copierClassName} copier;

    public UserServiceImpl(${copierClassName} beanCopier) {
        this.copier = beanCopier;
    }

    @Override
    public ${dtoClassName} info(String pk) {
        return copier.do2DTO(this.getById(pk));
    }

    @Override
    public ${dtoClassName} selectOne(${dtoClassName} dto) {
        LambdaQueryWrapper<${doClassName}> wrapper = new LambdaQueryWrapper<${doClassName}>()
${doEqCond}
                .last("limit 1");
        return copier.do2DTO(this.getOne(wrapper));
    }

    @Override
    public int countByCond(${dtoClassName} dto) {
        LambdaQueryWrapper<${doClassName}> wrapper = new LambdaQueryWrapper<${doClassName}>()
${doEqCond}
                ;
        return this.count(wrapper);
    }

    @Override
    public PageResult<${dtoClassName}> listByCond(${dtoClassName} dto) {
        Page<${doClassName}> pageCond = new Page<>(dto.getPageNum(), dto.getPageSize());
        Page<${doClassName}> page = this.lambdaQuery()
${doEqCond}
                .page(pageCond);
        return PageResult.build(page, copier::do2DTOList);
    }

    @Override
    public boolean update(${dtoClassName} dto) {
        return this.updateById(copier.dto2DO(dto));
    }

    @Override
    public boolean add(${dtoClassName} dto) {
        return this.save(copier.dto2DO(dto));
    }


    @Override
    public boolean addBatch(List<${dtoClassName}> dtos) {
        this.saveBatch(copier.dto2DOList(dtos),1000);
        return true;
    }

    @Override
    public int delBycond(${dtoClassName} dto) {
        LambdaQueryWrapper<${doClassName}> wrapper = new LambdaQueryWrapper<${doClassName}>()
${doEqCond}
;
        return this.getBaseMapper().delete(wrapper);
    }

    @Override
    public boolean del(String pk) {
        return this.removeById(pk) ;
    }

}
